#include "main.h"
//遍历存储至链表
struct Plink*my_plink(FILE*F)
{
	//创建头节点
	struct Plink*p=malloc(sizeof(struct Plink));
	if(p==NULL){printf("创建头节点失败\n");return NULL;}
	p->len=0;p->Next=NULL;
	//读取文件内信息,存储至链表
	struct Plink t={0,NULL};
	printf("%s\n",t.loginn.name);
	fseek(F,0,0);
	while(fscanf(F,"账号:%20s 密码:%20s\n",t.loginn.name,t.loginn.password)!=EOF)
	{
		printf("读取成功\n");
		printf("账号:%s  密码:%s\n",t.loginn.name,t.loginn.password);
		//sleep(2);
		struct Plink*p1=malloc(sizeof(struct Plink));
		if(p1==NULL){printf("节点创建失败\n");return NULL;}
		memcpy(p1->loginn.name,t.loginn.name,20);
		memcpy(p1->loginn.password,t.loginn.password,20);
		p1->Next=p->Next;
		p->Next=p1;
		p->len++;
	}
	return p;
}
//遍历查找                               
int my_login(struct Plink*P,struct login C_login)
{
	struct Plink* t=P->Next;
	int n=P->len;
	printf("%d\n",P->len);
	while(n>0)
	{
		//printf("对比\n");
		//printf("账号：%20s  密码：%20s\n",t->loginn.name,t->loginn.password);
		if(strcmp(t->loginn.name,C_login.name)==0)
		{
			printf("账号存在\n");
			if(strcmp(t->loginn.password,C_login.password)==0)
			{
				printf("密码正确\n");
				return 0;
			}
		}
		t=t->Next;
		n--;
	}
	return -1;
}
